//
//  TKYHomePageHeaderView.m
//  StationHouseHelper
//
//  Created by apple on 2018/6/19.
//  Copyright © 2018年 铁科院. All rights reserved.
//

#import "TKYHomePageHeaderView.h"
@interface TKYHomePageHeaderView()

@property (nonatomic, strong)UILabel *line;
@property (nonatomic, strong)UILabel *titleLabel;
@property (nonatomic, strong)UILabel *bottonLine;

/**
 质量
 */
@property (nonatomic, strong)UIButton * qualityButton;

/**
 安全
 */
@property (nonatomic, strong)UIButton *safetyButton;

/**
 起始时间
 */
@property (nonatomic, strong)UILabel *starDateLabel;


/**
 结束时间
 */
@property (nonatomic, strong)UILabel *endDateLabel;

@property (nonatomic, strong)UILabel *dateBottonLine;


/**
 新问题
 */
@property (nonatomic, strong)UILabel *questionLabel;
@property (nonatomic, strong)UILabel *questionNumLabel;

/**
 进行中
 */
@property (nonatomic, strong)UILabel *conductLabel;
@property (nonatomic, strong)UILabel *conductNumLabel;

/**
 进行中
 */
@property (nonatomic, strong)UILabel *finishLabel;
@property (nonatomic, strong)UILabel *finishNumLabel;

//升序按钮
@property (nonatomic, strong)UIButton *ascendingButton;

@property (nonatomic, strong)UIButton *descendingButton;

@property (nonatomic, strong)UILabel *numLabel;
@property (nonatomic, strong)UILabel *scoreLabel;



@end
@implementation TKYHomePageHeaderView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self addSubview:self.line];
        [self addSubview:self.titleLabel];
        [self addSubview:self.bottonLine];
        [self addSubview:self.safetyButton];
        [self addSubview:self.qualityButton];
        [self safetyButtonClick:self.safetyButton];
        [self addSubview:self.starDateLabel];
        [self addSubview:self.endDateLabel];
        [self addSubview:self.startDateView];
        [self addSubview:self.endDateView];
        [self addSubview:self.dateBottonLine];
        
        [self addSubview:self.questionLabel];
        [self addSubview:self.questionNumLabel];
        
        [self addSubview:self.conductLabel];
        [self addSubview:self.conductNumLabel];
        
        [self addSubview:self.finishLabel];
        [self addSubview:self.finishNumLabel];
        
        [self addSubview:self.ascendingButton];
        [self addSubview:self.descendingButton];
        
        [self ascendingButtonClick:self.ascendingButton];
        
        [self addSubview:self.numLabel];
        [self addSubview:self.scoreLabel];
        
        [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(kWidthScale *10);
            make.top.equalTo(self).with.offset(kHeightScale *13);
            make.height.mas_equalTo(kHeightScale *15);
            make.width.mas_equalTo(kWidthScale *2);
        }];
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.line.mas_right).with.offset(kWidthScale *5);
            make.top.equalTo(self).with.offset(kHeightScale *10);
            make.height.mas_equalTo(kHeightScale *20);
            make.width.mas_equalTo(kWidthScale *100);
        }];
        
        [self.bottonLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(kWidthScale *0);
            make.right.equalTo(self).with.offset(kHeightScale *0);
            make.top.equalTo(self.titleLabel.mas_bottom).with.offset(10);
            make.height.mas_equalTo(kHeightScale *1);
            //make.width.mas_equalTo(kWidthScale *100);
        }];
        
        
        
        [self.qualityButton mas_makeConstraints:^(MASConstraintMaker *make) {
            //make.left.equalTo(self).with.offset(kWidthScale *0);
            make.right.equalTo(self).with.offset(-kHeightScale *10);
            make.top.equalTo(self).with.offset(kHeightScale *10);
            make.height.mas_equalTo(kHeightScale *20);
            make.width.mas_equalTo(kWidthScale *50);
        }];

        [self.safetyButton mas_makeConstraints:^(MASConstraintMaker *make) {
            //make.left.equalTo(self).with.offset(kWidthScale *0);
            make.right.equalTo(self.qualityButton.mas_left).with.offset(kHeightScale *5);
            make.top.equalTo(self).with.offset(kHeightScale *10);
            make.height.mas_equalTo(kHeightScale *20);
            make.width.mas_equalTo(kWidthScale *50);
        }];
        [self.starDateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(kWidthScale *10);
            //make.right.equalTo(self.qualityButton.mas_left).with.offset(kHeightScale *5);
            make.top.equalTo(self.bottonLine.mas_bottom).with.offset(kHeightScale *5);
            make.height.mas_equalTo(kHeightScale *25);
            make.width.mas_equalTo(kWidthScale *55);
        }];
        
        //WithFrame:CGRectMake(_starDateLabel.kx_right+5, self.bottonLine.kx_bottom+kWidthScale *10, kWidthScale *120, kHeightScale *25)
        [self.startDateView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.starDateLabel.mas_right).with.offset(kWidthScale *5);
            //make.right.equalTo(self.qualityButton.mas_left).with.offset(kHeightScale *5);
            make.top.equalTo(self.starDateLabel.mas_top);
            make.height.mas_equalTo(kHeightScale *25);
            make.width.mas_equalTo(kWidthScale *110);
        }];
//
        [self.endDateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.startDateView.mas_right).with.offset(kWidthScale *15);
            //make.right.equalTo(self.qualityButton.mas_left).with.offset(kHeightScale *5);
            make.top.equalTo(self.startDateView.mas_top);
            make.height.mas_equalTo(kHeightScale *25);
            make.width.mas_equalTo(kWidthScale *55);
        }];
        
        [self.endDateView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.endDateLabel.mas_right).with.offset(kWidthScale *5);
            make.right.equalTo(self).with.offset(-kHeightScale *10);
            make.top.equalTo(self.starDateLabel.mas_top);
            make.height.mas_equalTo(kHeightScale *25);
            make.width.mas_equalTo(kWidthScale *110);

        }];
        
        [self.dateBottonLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(kWidthScale *0);
            make.right.equalTo(self).with.offset(0);
            make.top.equalTo(self.endDateView.mas_bottom).with.offset(kHeightScale *10);
            make.height.mas_equalTo(kHeightScale *1);
            //make.width.mas_equalTo(kWidthScale *110);
            
        }];
        
        [self.questionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(kWidthScale *0);
            make.right.equalTo(self.conductLabel.mas_left).with.offset(0);
            make.top.equalTo(self.dateBottonLine.mas_bottom).with.offset(kHeightScale *10);
            make.height.mas_equalTo(kHeightScale *20);
            make.width.mas_equalTo(kScreenWidth /3);

        }];
        
        [self.conductLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.questionLabel.mas_right).with.offset(kWidthScale *0);
            make.right.equalTo(self.finishLabel.mas_left).with.offset(0);
            make.top.equalTo(self.questionLabel.mas_top);
            make.height.mas_equalTo(kHeightScale *20);
            make.width.mas_equalTo(kScreenWidth /3);
        }];
        
        [self.finishLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.conductLabel.mas_right).with.offset(kWidthScale *0);
            make.right.equalTo(self).with.offset(0);
            make.top.equalTo(self.questionLabel.mas_top);
            make.height.mas_equalTo(kHeightScale *20);
            make.width.mas_equalTo(kScreenWidth /3);
        }];
        
        [self.questionNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(kWidthScale *0);
            make.right.equalTo(self.conductNumLabel.mas_left).with.offset(0);
            make.top.equalTo(self.questionLabel.mas_bottom).with.offset(kHeightScale *3);
            make.height.mas_equalTo(kHeightScale *20);
            make.width.mas_equalTo(kScreenWidth /3);
            
        }];
        
        [self.conductNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.questionNumLabel.mas_right).with.offset(kWidthScale *0);
            make.right.equalTo(self.finishLabel.mas_left).with.offset(0);
            make.top.equalTo(self.questionNumLabel.mas_top);
            make.height.mas_equalTo(kHeightScale *20);
            make.width.mas_equalTo(kScreenWidth /3);
        }];
        
        [self.finishNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.conductNumLabel.mas_right).with.offset(kWidthScale *0);
            make.right.equalTo(self).with.offset(0);
            make.top.equalTo(self.questionNumLabel.mas_top);
            make.height.mas_equalTo(kHeightScale *20);
            make.width.mas_equalTo(kScreenWidth /3);
        }];
        
        [self.scoreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).with.offset(-10);
            make.top.equalTo(self.questionNumLabel.mas_bottom).with.offset(kHeightScale*15);
            make.height.mas_equalTo(kHeightScale*20);
            make.width.mas_equalTo(kWidthScale*40);
        }];
        
        [self.numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.scoreLabel.mas_left).with.offset(-kWidthScale*10);
            make.top.equalTo(self.scoreLabel.mas_top);
            make.height.mas_equalTo(kHeightScale *20);
            make.width.mas_equalTo(kWidthScale *40);
        }];
        
        [self.ascendingButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(kWidthScale*10);
            make.top.equalTo(self.questionNumLabel.mas_bottom).with.offset(kWidthScale*15);;
            make.height.mas_equalTo(kHeightScale *20);
            make.width.mas_equalTo(kWidthScale *40);
        }];
        
        [self.descendingButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.ascendingButton.mas_right).with.offset(kWidthScale*3);
            make.top.equalTo(self.ascendingButton.mas_top);
            make.height.mas_equalTo(kHeightScale *20);
            make.width.mas_equalTo(kWidthScale *40);
        }];
       

    }
    return self;
}

- (UILabel *)line{
    if (_line == nil) {
        _line = [[UILabel alloc]init];
       // //#2D87FF 100%
        _line.backgroundColor = kRGBColor(45, 135, 255, 1);
    }
    return _line;
}

- (UILabel *)titleLabel{
    if(_titleLabel == nil) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.text = @"任务汇总";
        _titleLabel.font = Font(14);
        _titleLabel.textColor = kUIColorFromRGB(666666, 1);
    }
    return _titleLabel;
}

- (UILabel *)bottonLine{
    if(_bottonLine == nil) {
        _bottonLine = [[UILabel alloc]init];
        _bottonLine.backgroundColor = kRGBColor(237, 237, 237, 1);
    }
    return _bottonLine;
}

- (UIButton *)safetyButton{
    if (_safetyButton == nil) {
        _safetyButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_safetyButton setTitle:@"安全" forState:UIControlStateNormal];
        [_safetyButton setTitleColor:kUIColorFromRGB(666666, 1) forState:UIControlStateNormal];
        [_safetyButton setTitleColor:kRGBColor(45, 135, 255, 1) forState:UIControlStateSelected];
        [_safetyButton addTarget:self action:@selector(safetyButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        _safetyButton.titleLabel.font = Font(13);
    }
    return _safetyButton;
}


- (UIButton *)qualityButton{
    if (_qualityButton == nil) {
        _qualityButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_qualityButton setTitle:@"质量" forState:UIControlStateNormal];
        _qualityButton.titleLabel.font = Font(13);
        [_qualityButton setTitleColor:kUIColorFromRGB(666666, 1) forState:UIControlStateNormal];
        [_qualityButton setTitleColor:kRGBColor(45, 135, 255, 1) forState:UIControlStateSelected];
        [_qualityButton addTarget:self action:@selector(qualitButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _qualityButton;
}

- (UILabel *)starDateLabel{
    if (_starDateLabel == nil) {
        _starDateLabel = [[UILabel alloc]init];
        _starDateLabel.text = @"起始时间:";
        _starDateLabel.font = Font(12);
        _starDateLabel.textColor = kUIColorFromRGB(666666, 1);
    }
    return _starDateLabel;
}

- (UILabel *)endDateLabel{
    if (_endDateLabel == nil) {
        _endDateLabel = [[UILabel alloc]init];
        _endDateLabel.text = @"结束时间:";
        _endDateLabel.font = Font(12);
        _endDateLabel.textColor = kUIColorFromRGB(666666, 1);
    }
    return _endDateLabel;
}

- (TKYSelectedDateView *)startDateView{
    if (_startDateView == nil) {
        _startDateView = [[TKYSelectedDateView alloc]init];
    }
    return _startDateView;
}

- (TKYSelectedDateView *)endDateView{
    if (_endDateView == nil) {
        _endDateView = [[TKYSelectedDateView alloc]init];
    }
    return _endDateView;
}

- (UILabel *)dateBottonLine{
    if (_dateBottonLine == nil) {
        _dateBottonLine = [[UILabel alloc]init];
        _dateBottonLine.backgroundColor = kMainColour;
    }
    return _dateBottonLine;
}

- (UILabel *)questionLabel{
    if (_questionLabel == nil) {
        _questionLabel = [[UILabel alloc]init];
        _questionLabel.text = @"新问题";
        _questionLabel.font = Font(14);
        _questionLabel.textAlignment = NSTextAlignmentCenter;
        _questionLabel.textColor = kRGBColor(219, 81, 73, 1);
    }
    return _questionLabel;
}

- (UILabel *)questionNumLabel{
    if (_questionNumLabel == nil) {
        _questionNumLabel = [[UILabel alloc]init];
        _questionNumLabel.text = @"12";
        _questionNumLabel.font = Font(14);
        _questionNumLabel.textAlignment = NSTextAlignmentCenter;

        _questionNumLabel.textColor =  kRGBColor(219, 81, 73, 1);
    }
    return _questionNumLabel;
}

- (UILabel *)conductLabel{
    if (_conductLabel == nil) {
        _conductLabel = [[UILabel alloc]init];
        _conductLabel.text = @"进行中";
       // _conductLabel.backgroundColor = [UIColor redColor];
        _conductLabel.textAlignment = NSTextAlignmentCenter;
        _conductLabel.font = Font(14);
        _conductLabel.textColor = kRGBColor(45, 135, 255, 1);
    }
    return _conductLabel;
}

- (UILabel *)conductNumLabel{
    if (_conductNumLabel == nil) {
        _conductNumLabel = [[UILabel alloc]init];
        _conductNumLabel.text = @"12";
        _conductNumLabel.font = Font(14);
        _conductNumLabel.textAlignment = NSTextAlignmentCenter;
        _conductNumLabel.textColor = kRGBColor(45, 135, 255, 1);;
    }
    return _conductNumLabel;
}

- (UILabel *)finishLabel{
    if (_finishLabel == nil) {
        _finishLabel = [[UILabel alloc]init];
        _finishLabel.text = @"已完成";
        //_finishLabel.backgroundColor = [UIColor yellowColor];
        _finishLabel.font = Font(14);
        _finishLabel.textAlignment = NSTextAlignmentCenter;
        _finishLabel.textColor = kRGBColor(118, 168, 58, 1);
    }
    return _finishLabel;
}

- (UILabel *)finishNumLabel{
    if (_finishNumLabel == nil) {
        _finishNumLabel = [[UILabel alloc]init];
        _finishNumLabel.text = @"12";
        _finishNumLabel.font = Font(12);
        _finishNumLabel.textAlignment = NSTextAlignmentCenter;
        _finishNumLabel.textColor = kRGBColor(118, 168, 58, 1);
    }
    return _finishNumLabel;
}

- (UILabel *)numLabel{
    if (_numLabel == nil) {
        _numLabel = [[UILabel alloc]init];
        _numLabel.text = @"数量";
        _numLabel.textAlignment = NSTextAlignmentCenter;

        _numLabel.font = Font(11);
        _numLabel.textColor = kUIColorFromRGB(333333, 1);
    }
    return _numLabel;
}

- (UILabel *)scoreLabel{
    if (_scoreLabel == nil) {
        _scoreLabel = [[UILabel alloc]init];
        _scoreLabel.text = @"分数";
        _scoreLabel.font = Font(11);
        _scoreLabel.textColor = kUIColorFromRGB(333333, 1);
        _scoreLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _scoreLabel;
}

- (UIButton *)ascendingButton{
    if (_ascendingButton == nil) {
        _ascendingButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_ascendingButton setTitle:@"升序↑" forState:UIControlStateNormal];
        _ascendingButton.titleLabel.font = Font(12);
        [_ascendingButton setTitleColor:kRGBColor(102, 102, 102, 1) forState:UIControlStateNormal];
        [_ascendingButton setTitleColor:kRGBColor(45, 135, 255, 1) forState:UIControlStateSelected];
        [_ascendingButton addTarget:self action:@selector(ascendingButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [_ascendingButton tky_cornerWithRadius:3 borderColor:kRGBColor(45, 135, 255, 1) borderWidth:1];

    }
    return _ascendingButton;
}

- (UIButton *)descendingButton{
    if (_descendingButton == nil) {
        _descendingButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_descendingButton setTitle:@"降序↓" forState:UIControlStateNormal];
        _descendingButton.titleLabel.font = Font(12);
        [_descendingButton setTitleColor:kRGBColor(102, 102, 102, 1) forState:UIControlStateNormal];
        [_descendingButton setTitleColor:kRGBColor(45, 135, 255, 1) forState:UIControlStateSelected];
        [_descendingButton tky_cornerWithRadius:3 borderColor:kRGBColor(45, 135, 255, 1) borderWidth:1];
        [_descendingButton addTarget:self action:@selector(descendinButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _descendingButton;
}

#pragma mark-- 按钮的点击事件
//安全
- (void)safetyButtonClick:(UIButton *)button{
    button.selected = YES;
    self.qualityButton.selected = NO;
    if (self.safetyButtonBlock) {
        self.safetyButtonBlock(button);
    }
    // NSLog(@"安全");
}

//质量
- (void)qualitButtonClick:(UIButton *)button{
    button.selected = YES;
    self.safetyButton.selected = NO;
    if (self.qualityButtonBlock) {
        self.qualityButtonBlock(button);
    }
    //NSLog(@"质量");
}

//升序
- (void)ascendingButtonClick:(UIButton *)button{
    button.selected = YES;
    self.descendingButton.selected = NO;
    [_ascendingButton tky_cornerWithRadius:3 borderColor:kRGBColor(45, 135, 255, 1) borderWidth:1];
     [_descendingButton tky_cornerWithRadius:3 borderColor:kRGBColor(102, 102, 102, 1) borderWidth:1];

    if (self.ascendingButtonBlock) {
        self.ascendingButtonBlock(button);
    }
}

//降序
- (void)descendinButtonClick:(UIButton *)button{
    button.selected = YES;
    self.ascendingButton.selected = NO;
    [_descendingButton tky_cornerWithRadius:3 borderColor:kRGBColor(45, 135, 255, 1) borderWidth:1];
    [_ascendingButton tky_cornerWithRadius:3 borderColor:kRGBColor(102, 102, 102, 1) borderWidth:1];

    if (self.descendinButtonBlock) {
        self.descendinButtonBlock(button);
    }
}

@end
